/*
* Copyright @ 2014 com.iflysse.trains
* manger_v2.0 下午7:38:10
* All right reserved.
*
*/
package com.iflysse.service;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import com.iflysse.dao.UserRoleInfoDaome;
import com.iflysse.pojo.RoleInfo;
import com.iflysse.pojo.UserInfo;
import com.iflysse.pojo.UserRoleInfome;
import com.iflysse.utils.MySessionFactory;

/**
 * @desc: manger_v2.0
 * @author: Administrator
 * @createTime: 2014年11月24日 下午7:38:10
 * @history:
 * @version: v1.0
 */
public class UserRoleInfoServiceme {

	private SqlSessionFactory sf;
	
	public UserRoleInfoServiceme(){
		sf = MySessionFactory.getSessionFactory();
	}
	
	public List<RoleInfo> findRoleByUser(int userId){
		SqlSession session = sf.openSession();
		UserRoleInfoDaome mapper = session.getMapper(UserRoleInfoDaome.class);
		
		List<RoleInfo> list = mapper.findRoleByUser(userId);
		
		session.close();
		return list;
	}
	
	public void insertUserRole(UserRoleInfome userRole){
		SqlSession session = sf.openSession();
		UserRoleInfoDaome mapper = session.getMapper(UserRoleInfoDaome.class);
		
		mapper.insertUserRole(userRole);
		session.commit();
		session.close();
	}
	
	/**
	 * 
	 */
	public void TestDeleteAllUserRole(UserInfo user){
		SqlSession session = sf.openSession();
		UserRoleInfoDaome mapper = session.getMapper(UserRoleInfoDaome.class);
		
		mapper.deleteAllUserRole(user);
		session.commit();
		session.close();
	}
}
